import axios from "axios";

export const METHOD = {
  GET: "get",
  POST: "post",
};
const instance = axios.create({
  baseURL: "http://8.137.62.152",
  timeout: 5000,
});
// 导出一个异步函数request，用于发送请求
export const request = async (url, method, params) => {
  // 根据method的值，发送不同的请求
  switch (method) {
    case METHOD.GET:
      // 发送get请求
      return instance.get(url, { params, headers: {} });
    case METHOD.POST:
      return instance.post(url, params, {
        headers: {
          "Content-Type": "application/x-www-form-urlencoded",
        },
      });
    default:
      // 默认发送get请求
      return instance.get(url, { params, headers: {} });
  }
};

export default request;
